<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <input type="number" id="numberInput">
    <button onclick="compareNumbers()">猜</button>
    <span id="result"></span>
    <script>
        function compareNumbers() {
            var number = document.getElementById('numberInput').value;
            number = parseInt(number);
            var randomNum = Math.floor(Math.random() * 100) + 1;
            if (isNaN(number)) {
                alert("请输入一个有效的数字");
                return;
            } else {
                if (number < randomNum) {
                    document.getElementById('result').innerText = "大了";
                } else if (number > randomNum) {
                    document.getElementById('result').innerText = "小了";
                } else {
                    document.getElementById('result').innerText = "猜对了";
                }
            }
        }
    </script>
</body>
</html>